Listbox Demo 1

Level: Intermediate

by Brent Thorn

Home

A Contest!

Fast Bitmaps

Button Lesson

API Corner

Listbox Trivia

Listbox Demo 1

Listbox Demo 2

SpriteByte-Shooting

Qcard DLL-Lesson 1

DDOC Print Demo

Newsletter help

Index


This demo program shows how to change the background color and text color of a listbox at runtime. It requires the use of wmliberty.dll, by Brent Thorn, which is included in the zip archive of this newsletter.

    nomainwin
    a$(1)="Merry":a$(2)="Christmas"
    listbox #1.list,a$(),[loop],10,10,100,100
    open "wmliberty.dll" for dll as #wml
    open "Colored Listbox" for dialog as #1
    #1.list "font impact 12"
    #1 "trapclose [quit]"
    h1=hwnd(#1)
    hlist(0)=hwnd(#1.list)
    callback lpfnCB,OnCtlColorListbox(long,long,long,long),long
    clr=RGB(0,255,0) 'green
    calldll #gdi32,"CreateSolidBrush", _
        clr as long, hbr as long
    hbr(0)=hbr 'Store brush in a global variable.
    'Create subclass of parent window.
    'Trap the WM_CTLCOLORLISTBOX message.
    calldll #wml,"SetWMHandler",_
        h1 as long,_WM_CTLCOLORLISTBOX as long,_
        lpfnCB as long,hbr as long,r as long

[loop] 'Must use scan loop with WMLiberty
    scan
    calldll #kernel32,"Sleep",_
        100 as long,r as void
    goto [loop]

[quit]
    calldll #gdi32,"DeleteObject",_
        hbr as long,r as long
    close #1
    'Must close window before closing WMLiberty.
    close #wml
    end

function OnCtlColorListbox(hwnd,umsg,hdc,hlist)
    if hlist=hlist(0) then
        call SetTextColor hdc,RGB(255,0,0) 'red
        call SetBkColor hdc,RGB(0,255,0) 'green
        'Return a brush.
        OnCtlColorListbox=hbr(0)
    end if
end function

function RGB(r,g,b)
    RGB=r+256*g+65536*b
end function
sub SetBkColor hdc,clr
    calldll #gdi32,"SetBkColor",_
        hdc as long,clr as long,_
        r as long
end sub
sub SetTextColor hdc,clr
    calldll #gdi32,"SetTextColor",_
        hdc as long,clr as long,_
        r as long
end sub


Home

A Contest!

Fast Bitmaps

Button Lesson

API Corner

Listbox Trivia

Listbox Demo 1

Listbox Demo 2

SpriteByte-Shooting

Qcard DLL-Lesson 1

DDOC Print Demo

Newsletter help

Index